import Flutter
import UIKit

public class KmxyBasePlugin: NSObject, FlutterPlugin {
    
    private let locationManager: LocationManager
    // 声明为类的属性，用于存储channel
    private let channel: FlutterMethodChannel
    
    // 初始化方法，接收channel作为参数
    init(channel: FlutterMethodChannel) {
        self.channel = channel
        locationManager = LocationManager(channel: channel)
        super.init()
    }
    
    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "kmxy_base", binaryMessenger: registrar.messenger())
        // 创建实例时将channel传入
        let instance = KmxyBasePlugin(channel: channel)
        registrar.addMethodCallDelegate(instance, channel: channel)
    }

    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        switch call.method {
        case "startLocationService":
            locationManager.startLocationUpdates()
            result("成功")
        case "stopLocationService":
            locationManager.stopLocationUpdates()
            result("成功")
        default:
            result(FlutterMethodNotImplemented)
        }
    }
}
